{include file="public/public"}
<script>
	function confirmM() {
		var hotelId = $("#selHotel option:selected").val();
		var x = $('#addData_name').val();
		var symbol = $('.addData_fuhao:checked').val();
		var number = $('#addData_data').val();
		if(!symbol || !x || !number) {
			alert('信息不完善');
			return;
		}
		name.replace(/(^\s*)|(\s*$)/g, "");
		number.replace(/(^\s*)|(\s*$)/g, "");
		var con = confirm('确认保存该报警值？');
		if(!con) {
			return false;
		}
		$.post("__APP__/admin/addOperNotice", {
			'hotelId': hotelId,
			'x': x,
			'symbol': symbol,
			'number': number
		}, function(data) {
			if(data.result) {
				alert('添加成功');
				window.location.reload();
			} else {
				alert(data.msg);
				return false;
			}
		}, 'json');
	}

	function addData() {
		var hotelId = $("#selHotel option:selected").val();
		var nodata = $('#show_addData').attr('dataflag');
		if(nodata == 1) {
			alert('暂无该酒店数据 不能设置');
			return false;
		}
		$('#change_addData').hide();
		$('#show_addData').show();
		$('#addData_name').focus();
	}

	function deleteData(id) {
		var a = confirm('确认删除该项报警值吗');
		if(!a) {
			return false;
		}
		$.post("__APP__/admin/deleteOperNotice", {
			'id': id
		}, function(data) {
			if(data.result) {
				alert('删除成功');
				window.location.reload();
			} else {
				alert('删除失败');
			}
		}, "json");
	}

	function selHotelId() {
		var hotelId = $("#selHotel option:selected").val();
		window.location.href = "__APP__/admin/operationNotice?hotelId=" + hotelId;
	}
</script>
<div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
	<div class="layui-body layui-tab-content site-demo site-demo-body">
		<div class="layui-tab-item layui-show">
			<div class="layui-main">
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
				</fieldset>
				<span class="layui-breadcrumb">
                    <a href="__APP__/{$menuConfigArry['functionMod']}/{$menuConfigArry['menuLabel']}">{$menuConfigArry['pmenuName']}</a>
                    <a><cite>{$menuConfigArry['menuName']}</cite></a>
                </span>
				<hr>
				<div>
					<label>选择酒店：</label>
					<select id="selHotel" onchange="selHotelId();" data-placeholder="选择酒店" class="chosen-select" style="width:350px;" tabindex="2">
						<option value=""></option>
						<?php
			  				if(isset($hotels)){
			  					foreach($hotels as $val){
  						?>
							<option <?php if($val[ 'id']==$hotelId) echo "selected=selected"; ?> value="{$val['id']}">{$val['hotel']}</option>
							<?php
			  					}
			  				}	
			  			?>
					</select>
				</div>
				<?php
  		if($noticeArr){
?>
					<table class="layui-table" lay-skin="line">
						<thead>
							<tr>
								<td>参数</td>
								<td>报警值</td>
								<td></td>
							</tr>
						</thead>
						<?php
			foreach($noticeArr as $key=>$value){
?>
							<tr id>
								<td>{$key}</td>
								<td>{$value['value']}</td>
								<td>
									<?php
			if($value['name']>0){
			?>
									<a href="#" class="layui-btn layui-btn-sm" onclick='deleteData("{$value[' id ']}")'>删除</a>
									<?php
			}else{
			?>
									<span>默认值</span>
									<?php
			}
			?>

								</td>
							</tr>
							<?php
		}
?>
					</table>
					<?php
	}else{
	?>
					<p>未设置任何警报值</p>
					<?php
	}
  ?>
						<?php
  if(!isset($namelist)){
  ?>
							<p style='padding-left:30px;margin-top:10px;'>暂时无法设置</p>
							<?php
  }else if(empty($namelist)){
	?>
								<p style='padding-left:30px;margin-top:10px;'>已无可设置项 如需修改 请先删除</p>
								<?php
   }else{
  ?>
									<p id='change_addData' style='padding-left:30px;margin-top:10px;'><input type='button' value='增加数据' class='layui-btn layui-btn-warm' onclick="addData();" /></p>
									<div id='show_addData' style='display:none;' appsel="{$appselect}">
										<table class="layui-table" lay-skin="line">
											<tr>
												<td>参数名</td>
												<td>符号</td>
												<td>报警值(百分比请先修改为小数)</td>
												<td></td>
											</tr>
											<tr>
												<td>
													<select id='addData_name'>
														<?php
      			foreach($namelist as $value){
      			?>
															<option>{$value}</option>
															<?php
      			}
      			?>
													</select>
												</td>
												<td style='text-align: left'>
													<input type='radio' name='addData_sybol' class='addData_fuhao' value=1 />>=
													<input type='radio' name='addData_sybol' class='addData_fuhao' value=2 />
													<=< /td>
														<td style='text-align: left;'><input type='text' size=6 id='addData_data' /></td>
														<td>
															<input id='close_change_add' type='button' class='layui-btn layui-btn-warm' value='提交' onclick="confirmM()" />
														</td>
											</tr>
										</table>
									</div>
									<?php 
  }
  ?>

			</div>
		</div>
	</div>
</div>
<!--<script src="__PUBLIC__/new_select/chosen.jquery.js" type="text/javascript"></script>-->
<script src="__PUBLIC__/new_select/prism.js" type="text/javascript"></script>

<script type="text/javascript">
	var config = {

		'.chosen-select': {},

		'.chosen-select-deselect': {
			allow_single_deselect: true
		},

		'.chosen-select-no-single': {
			disable_search_threshold: 10
		},

		'.chosen-select-no-results': {
			no_results_text: 'Oops, nothing found!'
		},

		'.chosen-select-width': {
			width: "95%"
		}

	}

	for(var selector in config) {

		$(selector).chosen(config[selector]);

	}
</script>